import 'package:flutter/material.dart';
import 'package:flutter_application_1/config/app_colors.dart';
import 'package:flutter_application_1/utils/user_type.dart';

class AvatarRoleName extends StatelessWidget {
  final String coverPictureUrl;
  final String type;
  final String nickname;
  final bool showType;
  const AvatarRoleName(
      {Key? key,
      required this.coverPictureUrl,
      required this.type,
      required this.nickname,
      this.showType = true})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        _avatar(),
        SizedBox(
          width: 3,
        ),
        Offstage(
          offstage: !showType,
          child: _role(),
        ),
        SizedBox(
          width: 3,
        ),
        Expanded(
          child: _name(),
        )
      ],
    );
  }

  Widget _avatar() {
    return Container(
      width: 20,
      height: 20,
      child: ClipOval(
        child: FadeInImage.assetNetwork(
            placeholder: "assets/images/common/lazy-1.png",
            image: coverPictureUrl),
      ),
    );
  }

  Widget _role() {
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 4),
      decoration: BoxDecoration(
        color: UserType.fromColor(type),
        borderRadius: BorderRadius.circular(3),
      ),
      child: Text(
        UserType.fromCn(type),
        style: const TextStyle(
          color: Colors.white,
          fontSize: 10,
        ),
      ),
    );
  }

  Widget _name() {
    return Container(
      child: Text(
        nickname,
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
        style: const TextStyle(
          color: AppColors.unactive,
          fontSize: 14,
        ),
      ),
    );
  }
}
